﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Super_Pong.BaseClasses;
using Microsoft.Xna.Framework.Graphics;
using Super_Pong.Classes;


/*
 * AVISO:
 * ESSA CLASSE NAO ESTÁ TERMINADA! NÃO MECHA SEM A AUTORIZAÇÃO DO AUTOR!
*/

namespace Game.Classes.Entities.GameEntities
{
    public class Ball : Entity
    {
        #region Atributos
        private float size;
        private float maxVelocity;
        private float radius;
        private GameWindow gameWindow;
        #endregion


        #region Construtor
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="position">ball's initial position</param>
        /// <param name="sprite">the image</param>
        /// <param name="speed">initial speed</param>
        /// <param name="maxVelocity">speed limit</param>
        /// <param name="size">scale</param>
        /// <param name="direction">its direction</param>
        public Ball(Vector2 position, Animation sprite, float speed, float maxVelocity, float size, Vector2 direction, float radius,GameWindow gw)
        {
            setPosition(position);
            setAnimation(sprite);
            setSpeed(speed);
            this.maxVelocity = maxVelocity;
            this.size = size;
            setDirection(direction);
            this.radius = radius;
            this.gameWindow = gw;
        }
        #endregion


        #region Metodos
        public override void collide(Entity e)
        {
        }

        public void checkWindowColision()
        {
            if (getPosition().Y < 0 || getPosition().Y + getHeight() > gameWindow.ClientBounds.Height)
            {
                setDirection(getDirection().X, -getDirection().Y);
            }
            if (getPosition().X < 0 || getPosition().X + getWidth() > gameWindow.ClientBounds.Width)
            {
                setDirection(-getDirection().X, getDirection().Y);
            }
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(getAnimation().GetCurrentImage(), getPosition(), Color.White);
        }

        public override void Update(GameTime elapsedTime)
        {
            setPosition(getPosition() + getSpeed() * getDirection() * elapsedTime.ElapsedGameTime.Milliseconds/1000);

            checkWindowColision();             
        }


        #region Gets e Sets
        public float GetRadius()
        {
            return this.radius;
        }
        #endregion
        #endregion
    }
}
